//===============================================================================
// Microsoft patterns & practices
// Smart Client Software Factory 2010
//===============================================================================
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
using System;
using System.IO;
using GlobalBank.Infrastructure.Library.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GlobalBank.Infrastructure.Library.Tests.Services
{
	[TestClass]
	public class ProfileCatalogModuleInfoStoreFixture
	{
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void NullFileThrows()
		{
			ProfileCatalogModuleInfoStore store = new ProfileCatalogModuleInfoStore();

			store.CatalogFilePath = null;
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentException))]
		public void EmptyStringThrows()
		{
			ProfileCatalogModuleInfoStore store = new ProfileCatalogModuleInfoStore();

			store.CatalogFilePath = "";
		}

		[TestMethod]
		public void DefaultCatalogFilePathIsProfileCatalogDotXml()
		{
			ProfileCatalogModuleInfoStore store = new ProfileCatalogModuleInfoStore();

			Assert.AreEqual("profilecatalog.xml", store.CatalogFilePath.ToLowerInvariant());
		}

		[TestMethod]
		public void ReadsContentsOfFileFromDiskAsString()
		{
			string filename = Path.GetTempFileName();
			string contents = "1 2 3\n4 5\n 6";
			File.WriteAllText(filename, contents);
			ProfileCatalogModuleInfoStore store = new ProfileCatalogModuleInfoStore();
			store.CatalogFilePath = filename;

			string results = store.GetModuleListXml();

			Assert.AreEqual(contents, results);
		}

		[TestMethod]
		public void ReturnsNullWhenFileNotPresent()
		{
			string filename = Guid.NewGuid().ToString();
			ProfileCatalogModuleInfoStore store = new ProfileCatalogModuleInfoStore();
			store.CatalogFilePath = filename;

			string results = store.GetModuleListXml();

			Assert.IsNull(results);
		}

		// TODO:
		// Log warning message when file isn't present?
	}
}
